package com.example.fastshare.entities;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.text.format.Time;

public class MessageEntity implements Comparable<MessageEntity> {
	// DB Fields name
	public final static String ID = "id";
	public final static String MESSAGE_TYPE = "message_type";
	public final static String USER_ID = "user_id";
	public final static String GROUP_ID = "gourp_id";
	public final static String IMAGE_ID = "image_id";
	public final static String CONTENT = "content";
	public final static String TIME = "time";
	public final static String TABLE_NAME = "tblMessage";

	// Constant Field
	private String mID;
	private String mMessage_type;
	private String mUser_ID;
	private String mGroup_ID;
	private String mImage_ID;
	private String mContent;
	private String mTime;

	// Null Constructor
	public MessageEntity() {
		super();
	}

	// Full Constructor
	public MessageEntity(String mID, String mMessage_type, String mUser_ID,
			String mGourp_ID, String mImage_ID, String mContent, Date mTime) {
		super();
		this.mID = mID;
		this.mMessage_type = mMessage_type;
		this.mUser_ID = mUser_ID;
		this.mGroup_ID = mGourp_ID;
		this.mImage_ID = mImage_ID;
		this.mContent = mContent;
		this.mTime = mTime.toString();
	}

	public MessageEntity(String mID, String mMessage_type, String mUser_ID,
			String mGourp_ID, String mImage_ID, String mContent) {
		super();
		this.mID = mID;
		this.mMessage_type = mMessage_type;
		this.mUser_ID = mUser_ID;
		this.mGroup_ID = mGourp_ID;
		this.mImage_ID = mImage_ID;
		this.mContent = mContent;
		this.mTime = new Date().toString();
	}

	public MessageEntity(String mID, Boolean isSend, String mUser_ID,
			String mGourp_ID, String mImage_ID, String mContent, Time m_Time) {
		super();
		this.mID = mID;
		if (isSend) {
			this.mMessage_type = "SEND";
		} else {
			this.mMessage_type = "RECEIVE";
		}

		this.mUser_ID = mUser_ID;
		this.mGroup_ID = mGourp_ID;
		this.mImage_ID = mImage_ID;
		this.mContent = mContent;
		m_Time.setToNow();
		this.mTime = m_Time.hour + ":" + m_Time.minute + ":" + m_Time.second;
	}

	public MessageEntity(String mID, String mMessage_type, String mUser_ID,
			String mGourp_ID, String mImage_ID, String mContent, String mTime) {
		super();
		this.mID = mID;
		this.mMessage_type = mMessage_type;
		this.mUser_ID = mUser_ID;
		this.mGroup_ID = mGourp_ID;
		this.mImage_ID = mImage_ID;
		this.mContent = mContent;
		this.mTime = mTime;
	}

	public String getID() {
		return mID;
	}

	public void setID(String mID) {
		this.mID = mID;
	}

	public String getMessage_type() {
		return mMessage_type;
	}

	public void setMessage_type(String mMessage_type) {
		this.mMessage_type = mMessage_type;
	}

	public boolean isSend() {
		if (this.mMessage_type.equals("send")) {
			return true;
		}
		return false;
	}

	public String getUser_ID() {
		return mUser_ID;
	}

	public void setUser_ID(String mUser_ID) {
		this.mUser_ID = mUser_ID;
	}

	public String getGourp_ID() {
		return mGroup_ID;
	}

	public void setGourp_ID(String mGourp_ID) {
		this.mGroup_ID = mGourp_ID;
	}

	public String getImage_ID() {
		return mImage_ID;
	}

	public void setImage_ID(String mImage_ID) {
		this.mImage_ID = mImage_ID;
	}

	public String getContent() {
		return mContent;
	}

	public void setContent(String mContent) {
		this.mContent = mContent;
	}

	public Date getTime() throws ParseException {
		DateFormat mDateFormat = new SimpleDateFormat(
				"EEE MMM dd HH:mm:ss zzz yyyy");
		Date mDate = (Date) mDateFormat.parse(mTime);
		return mDate;
	}

	public String getTimeInString() {
		return this.mTime;
	}

	public void setTime(Date mTime) {
		this.mTime = mTime.toString();
	}

	public void setTime(String mTime) {
		this.mTime = mTime;
	}

	@Override
	public int compareTo(MessageEntity another) {
		int result = 0;
		try {
			result = this.getTime().compareTo(another.getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (result != 0) {
			return result;
		} else {
			// TODO
			// Add code to implement the comparision
		}
		return 0;
	}

}
